﻿package com.oneko.reproductores {
	import flash.display.SimpleButton;
	import flash.net.URLRequest;
	import flash.media.*;
	import flash.events.MouseEvent;
		
	public class AudioPlayer extends SimpleButton{
		
		private const qBuffer=1;
		private const qIni=0;
		private const qLoop=1;
		
		private var so:Sound;
		private var urlR:URLRequest;
		private var _url:String;
		private var buffer:SoundLoaderContext;
		private var ini:Number;
		private var loop:Number;
		private var sc:SoundChannel;
	  
		public function set url(u:String):void{
			urlR = new URLRequest(u);
			_url=u;
		}
		public function get url():String{
			return _url;
		}
		// Private Properties:
		
	
		// Initialization:
		public function AudioPlayer(w:Number,h:Number) { 
			buffer = new SoundLoaderContext(qBuffer*1000);
			ini = qIni*1000;
         	loop = (qLoop >= 0) ? qLoop : int.MAX_VALUE;
		 
			addEventListener(MouseEvent.CLICK,playAudio);
		}
		
		private function playAudio (evt) {
			this.stopAudio();
			so = new Sound(urlR, buffer);
			sc = so.play(ini, loop);
		}
		
		public function stopAudio () {
			if (null != sc) {
				sc.stop();
			}
		}
	}
}